package com.sky.service.impl;

import com.sky.context.BaseContext;
import com.sky.entity.AddressBook;
import com.sky.mapper.AddressBookMapper;
import com.sky.service.AddressBookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AddressBookServiceImpl implements AddressBookService {
@Autowired
private AddressBookMapper addressBookMapper;
    @Override
    public void addAddress(AddressBook addressBook) {
        addressBook.setUserId(BaseContext.getCurrentId());
        addressBook.setIsDefault(0);
        addressBookMapper.addAddress(addressBook);

    }

    @Override
    public List<AddressBook> list(AddressBook addressBook) {
        return addressBookMapper.list(addressBook);


    }



    @Override
    public void setDefault(AddressBook addressBook) {
      addressBook.setIsDefault(0);
      addressBook.setUserId(BaseContext.getCurrentId());
      addressBookMapper.updateIsDefault(addressBook);

      addressBook.setIsDefault(1);
      addressBookMapper.update(addressBook);


    }

    @Override
    public void update(AddressBook addressBook) {
        addressBookMapper.update(addressBook);


    }

    @Override
    public void deleteById(Long id) {
        addressBookMapper.deleteById(id);

    }

    @Override
    public AddressBook getById(Long id) {
        return addressBookMapper.getById(id);

    }
}
